package servlets;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import database.DatabaseOperations;

public class ViewJobs extends HttpServlet {

	Connection conn = null;
	Statement stmt = null;
	private DatabaseOperations databaseOperations;
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		databaseOperations = new DatabaseOperations();
		try {
//			response.setContentType("text/html");
			PrintWriter out = response.getWriter();
//			String title = "Database Result";
//			String docType = "<!doctype html public \"-//w3c//dtd html 4.0 "
//					+ "transitional//en\">\n";
//			out.println(docType + "<html>\n" + "<head><title>" + title
//					+ "</title></head>\n" + "<body bgcolor=\"#f0f0f0\">\n"
//					+ "<h1 align=\"center\">" + title + "</h1>\n");
//			// Set response content type
//			for(String s: databaseOperations.getAllJobs()){
//				out.println(s);
//				out.println("<br>");
//				out.println("<br>");
//			}
//			
//			out.println("<a href='http://localhost:8080/RoadRunner/'> Go to home page </a>");
//			out.println("</body></html>");
			
			response.setContentType("application/json");
		    response.setCharacterEncoding("UTF-8");
		    response.getWriter().write(databaseOperations.getAllJobs().toString()); 
		} finally {
			databaseOperations.closeConnection();
		}
	}
	

}
